from django.db import models


# 医院表
class hospital(models.Model):
    hos_id = models.IntegerField(verbose_name="医院编号", primary_key=True)
    hos_name = models.CharField(verbose_name="医院名称", max_length=64)
    hos_province = models.CharField(verbose_name="所在省份", max_length=64)
    hos_city = models.CharField(verbose_name="所在城市", max_length=64)
    hos_email = models.CharField(verbose_name="联系方式", max_length=64)


# 用户表

class users(models.Model):
    user_id = models.IntegerField(primary_key=True, verbose_name="用户编号")
    user_name = models.CharField(verbose_name="用户名", max_length=64)
    user_pwd = models.CharField(verbose_name="密码", max_length=64)
    user_real_name = models.CharField(verbose_name="真实姓名", max_length=32)
    user_email = models.CharField(verbose_name="用户邮箱", max_length=64)
    user_tel = models.CharField(verbose_name="用户电话", max_length=11)


# 主科室表
class main_department(models.Model):
    main_dep_id = models.IntegerField(primary_key=True, verbose_name="主科室编号")
    main_dep_name = models.CharField(verbose_name="主科室名称", max_length=64)

    def __str__(self):
        return self.main_dep_name


# 副科室表
class sub_department(models.Model):
    sub_dep_id = models.IntegerField(primary_key=True, verbose_name="次科室编号")
    sub_dep_name = models.CharField(verbose_name="次科室名称", max_length=32)

    main_dep = models.ForeignKey(verbose_name="主科室名称", to="main_department", to_field="main_dep_id",
                                 on_delete=models.CASCADE, blank=True)


# 医生表
class doctors(models.Model):
    doc_id = models.IntegerField(primary_key=True, verbose_name="医生编号")
    doc_pwd = models.CharField(verbose_name="医生密码", max_length=32)
    doc_name = models.CharField(verbose_name="医生姓名", max_length=32)
    doc_sex = (
        (1, '男'),
        (2, '女'),
    )
    doc_tel = models.CharField(verbose_name="医生电话", max_length=11)
    doc_email = models.CharField(verbose_name="医生邮箱", max_length=64)
    doc_image = models.CharField(verbose_name="医生头像", max_length=200)
    doc_main_depart = models.ForeignKey(verbose_name="主科室名称", to="main_department", to_field="main_dep_id",
                                        on_delete=models.CASCADE, blank=True)
    doc_sub_depart = models.ForeignKey(verbose_name="次科室名称", to="sub_department", to_field="sub_dep_id",
                                       on_delete=models.CASCADE, blank=True)


# 病例表
class cases(models.Model):
    cases_id = models.IntegerField(verbose_name="病例编号", primary_key=True)
    cases_name = models.CharField(verbose_name="病例名称", max_length=200)
    cases_introduction = models.TextField(verbose_name="病例简介")
    cases_alias = models.CharField(verbose_name="别名", max_length=32)

    cases_medical_insurance = (
        (1, "是"),
        (2, "否"),
    )

    cases_infectivity = (
        (1, "是"),
        (2, "否"),
    )
    cases_fre_occ_population = models.CharField(verbose_name="多发人群", max_length=64)
    cases_related_symptoms = models.TextField(verbose_name="相关症状")

    # 主科室外键
    cases_dep_main = models.ForeignKey(verbose_name="主科室名称", to="main_department", to_field="main_dep_id",
                                       on_delete=models.CASCADE, blank=True)
    # 次科室名称
    cases_dep_sub = models.ForeignKey(verbose_name="次科室名称", to="sub_department", to_field="sub_dep_id",
                                      on_delete=models.CASCADE, blank=True)

    cases_doc = models.ForeignKey(verbose_name="医生姓名", to="doctors", to_field="doc_id", on_delete=models.CASCADE)
